package com.huiyujiaoyu.powertime.ui.my;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.huiyujiaoyu.base.BaseActivity;
import com.huiyujiaoyu.powertime.R;
import com.huiyujiaoyu.powertime.model.ConfigBean;
import com.huiyujiaoyu.powertime.model.UserInfoBean;
import com.huiyujiaoyu.util.ActivityUtil;
import com.huiyujiaoyu.util.DisplayUtil;
import com.huiyujiaoyu.util.MyClickableSpan;
import com.huiyujiaoyu.util.ResourceUtil;
import com.huiyujiaoyu.widget.GridSpacingItemDecoration;
import com.huiyujiaoyu.widget.LlkjToolBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.huiyujiaoyu.powertime.model.TestDataUtils.getCBS;

/**
 * Created by win7 on 2017/6/18.
 * 我的收藏
 */

public class MyVipPayActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    LlkjToolBar mToolbar;
    @BindView(R.id.tv_money)
    TextView mTvMoney;
    @BindView(R.id.tv_symoney)
    TextView mTvSymoney;
    @BindView(R.id.rv_content)
    RecyclerView mRvContent;
    private BaseQuickAdapter<ConfigBean,BaseViewHolder> adapter;
    private List<ConfigBean> moneys;
    private int selectPos;
    public static void launch(Context context) {
        ActivityUtil.startActivity(context, MyVipPayActivity.class);
    }

    @Override
    protected void initView() {
        super.initView();
        setToolbar(mToolbar);
        mToolbar.setToolBar("充值", true, "", R.mipmap.icon_titlebar_back, false, "", LlkjToolBar.isNull);
        mTvMoney.setText(UserInfoBean.getInstance().getBalance()+"元");
        MyClickableSpan.setText(mTvSymoney,String.format(ResourceUtil.getContent(mContext,R.string.chayue),"50"));
        moneys = new ArrayList<>();
        moneys.addAll(getCBS(6));
        adapter = new BaseQuickAdapter<ConfigBean, BaseViewHolder>(R.layout.cell_textview,moneys) {
            @Override
            protected void convert(BaseViewHolder helper, ConfigBean item) {
                TextView itemView =  helper.getView(R.id.tv_item_money);
                itemView.setText(item.money+"元");
                itemView.setSelected(item.isOk);
            }
        };
        mRvContent.setLayoutManager(new GridLayoutManager(mContext, 3));
        mRvContent.addItemDecoration(new GridSpacingItemDecoration(3,DisplayUtil.dip2px(mContext,10),true,false));
        mRvContent.setAdapter(adapter);

    }

    @Override
    protected void initListener() {
        super.initListener();
        mRvContent.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                selectPos = position;
                setSelect(selectPos);
            }
    });
    }
    
    private void setSelect(int pos){
        for (int i = 0; i < moneys.size(); i++) {
            moneys.get(i).isOk = i==pos;
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_vip_pay;
    }


    @OnClick(R.id.btn_topay)
    public void onViewClicked(View v) {
        switch (v.getId()) {
            case R.id.btn_topay:
                break;
        }
    }

}
